import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		username: '小虎',
		avatar: 'http://127.0.0.1:3000/static/default/1.svg',
		id: "63a3eba42eb31123b4e5439d",
		FriendList: [{
				"_id": "63a3f82f2eb31123b4e5439f",
				"name": "小李",
				"email": "xiaoli@qq.com",
				"avatar": "http://127.0.0.1:3000/static/default/user.png",
				"news": "炫丽的彩虹，永远都在雨过天晴后。",
				"time": "2022-12-22T06:45:10.001Z"
			},
			{
				"_id": "63a3f84d2eb31123b4e543a1",
				"name": "小明",
				"email": "xiaoming@163.com",
				"avatar": "http://127.0.0.1:3000/static/default/3.svg",
				"time": "2022-12-22T07:17:23.723Z"
			},
			{
				"_id": "63a3f8612eb31123b4e543a3",
				"name": "小花",
				"email": "xiaohua@qq.com",
				"avatar": "http://127.0.0.1:3000/static/default/4.svg",
				"time": "2022-12-25T07:57:53.182Z"
			}

		],
		NewFriend: [],
		group: [{
			"groupId": "63a9411b672fe88d4c3de84e",
			"avatar": "group.png",
			"name": "一个人"
		}],
		chat: {
			"_id": "63a3f82f2eb31123b4e5439f",
			"name": "小李",
			"email": "xiaoli@qq.com",
			"avatar": "http://127.0.0.1:3000/static/default/user.png",
			"news": "炫丽的彩虹，永远都在雨过天晴后。",
			"time": "2022-12-22T06:45:10.001Z"
		}
		// chat: {
		// 	"groupId": "63c104e5dbfe06f010d6c552",
		// 	"avatar": "http://127.0.0.1:3000/static/default/group.svg",
		// 	"name": "一个人",
		// 	"time": "2023-01-13T06:58:20.759Z"
		// }
	},
	mutations: {
		changeUser(state, str) {
			state.username = str
		},
		changeavatar(state, str) {
			state.avatar = str
		},
		changeFriendList(state, arr) {
			state.FriendList = arr
		},
		changeid(state, id) {
			state.id = id
		},
		changeNewFriend(state, arr) {
			state.NewFriend = arr
		},
		deleteoneNewFriend(state, index) {
			state.NewFriend.splice(index, 1)
		},
		changegroup(state, arr) {
			state.group = arr
		},
		changechat(state, obj) {
			state.chat = obj
		}
	},
	actions: {
		changeUseraction({
			commit
		}, str) {
			commit('changeUser', str)
		},
		changeavataraction({
			commit
		}, str) {
			commit('changeavatar', str)
		},
		changeFriendListaction({
			commit
		}, arr) {
			commit('changeFriendList', arr)
		},
		changeidaction({
			commit
		}, id) {
			commit('changeid', id)
		},
		changeNewFriendaction({
			commit
		}, arr) {
			commit('changeNewFriend', arr)
		},
		deleteoneNFaction({
			commit
		}, index) {
			commit('deleteoneNewFriend', index)
		},
		changegroupaction({
			commit
		}, arr) {
			commit('changegroup', arr)
		},
		changechataction({
			commit
		}, obj) {
			commit('changechat', obj)
		}
	}
})
export default store
